package com.example.boot0501.controller;

import com.example.boot0501.mapper.UserMapper;
import com.example.boot0501.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;
    @RequestMapping("/reg")
    public int reg(@RequestBody User user){
        User u = mapper.select(user.getUsername());
        if(u==null){
            mapper.insert(user);
            System.out.println("user = " + user);
            return 1;
        }
       return 2;
    }
    @RequestMapping("/check")
    public int check(String username){
        User u = mapper.select(username);
       return u==null?1:2;
    }
    @RequestMapping("/login")
    public int login(@RequestBody User user){
        User u = mapper.select(user.getUsername());
        if(u != null){
            if(user.getPassword().equals(u.getPassword())){
                return 1;
            }
            return 2;
        }
        return 3;
    }

}
